package com.example.springboottest;

import com.example.springboottest.core.util.DateUtil;
import com.example.springboottest.util.CronUtil;
import com.example.springboottest.util.FtpHelper;
import com.example.springboottest.util.StringUtil;
import com.example.springboottest.util.Zip4jUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Date;

@SpringBootTest
@RunWith(SpringRunner.class)
public class test {
    @Test
    public void test() {
        int x = 30;

        do {
            System.out.print("value of x : " + x);
            x++;
            System.out.print("\n");
        } while (x < 20);
    }


    @Autowired
    FtpHelper ftpHelper;
    // 测试文件传输
    @Test
    public void test1() {


        String host = "127.0.0.1";
        int port = 21;
        String username = "ftpTest";
        String password = "ftpTest";
        //登录ftp服务器，使用用户名 和密码  C:\ftp
        if (ftpHelper.login(host,port,username, password)) {

            // 名称
            String splicingFileName = StringUtil.splicingFileName("88.xml", "V0001", DateUtil.sdfDateTime(new Date()), RandomStringUtils.randomAlphanumeric(5));

//            boolean b = ftpHelper.uploadFile("D:\\xml\\88.xml", "/ftpServer", splicingFileName);
            System.out.println(splicingFileName);
            boolean b = ftpHelper.uploadFile("D:\\xml\\ZBZK_KJHQBZGX__test_0601.user0601-REP_ZB_TS--FILE__00000001_____20230605_161238__0631d622-b1a2-4f58-92d3-f4467b62027c.zip_____00000001OF1", "/ftpPath", "ZBZK_KJHQBZGX__test_0601.user0601-REP_ZB_TS--FILE__00000001_____20230605_161238__0631d622-b1a2-4f58-92d3-f4467b62027c.zip_____00000001OF1");
            System.out.println(b);


        }

    }


    @Test
    public void test2() {


        String splicingFileName = StringUtil.splicingFileName("88.xml", "V0001", DateUtil.sdfDateTime(new Date()), RandomStringUtils.randomAlphanumeric(5));

        System.out.println(splicingFileName);

        // 随机的数字字符串
        System.out.println(RandomStringUtils.randomNumeric(5));
        //
        System.out.println(RandomStringUtils.randomAscii(4));

        //生成指定长度的字母和数字的随机组合字符串
        System.out.println(RandomStringUtils.randomAlphanumeric(5));


        System.out.println(DateUtil.sdfDateTime(new Date()));


    }




    /**
     * 测试cron表达式的util类测试
     *
     * @author liuyishuo
     * @date 2023/5/16 20:48
     * @return void
     **/
    @Test
    public void cronUtils()throws Exception{

                /* {"cron":"0 0 0 31 * ?","duration":2678400}*/
                /* {"cron":"0 20 0 ? * 7","duration":604740}*/
                /* {"cron":"0 20 0 * * ?","duration":86340}*/
                /* {"cron":"0 59 23 L * ?","duration":2678340} */
//                String cron="cron\":\"0 59 23 L * ?";
                String cron="* 5 * * * ?";
                int duration=0;
                String newCron= CronUtil.cronExpressionPlusDuration(cron,duration);
                System.out.println(newCron);


    }

    /**
     * 压缩包测试
     * @author liuyishuo
     * @date 2023/6/2 16:08
     * @return void
     **/
    @Test
    public void fileToZip(){
        /**
         *  sourceFilePath :待压缩的文件路径   zipFilePath    :压缩后存放路径  fileName       :压缩后文件的名称
         **/
        try {
            String sourceFilePath = "88.xml";
            String zipFilePath = "D:\\xml\\";
            String targetPath = "D:\\";
            String fileName = "";

//            String fn = FileToZip.zip(sourceFilePath, zipFilePath,false, null);
//        String fn = FileToZip.fileToZip(sourceFilePath, zipFilePath, fileName);
//            Zip4jUtils.zipFileNotDelFile(sourceFilePath,"67890305.zip.",zipFilePath,false);
            Zip4jUtils.zipDir("22.zip",zipFilePath,targetPath,false);

        }catch (Exception e){
            System.out.println(e);
        }
    }


    @Test
    public void dateStr(){


        String dateStr = DateUtil.formatDate(new Date(), "yyyyMMdd_HHmmss");


        System.out.println(dateStr);

    }



}
